package com.example.myapplication;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;


public class settingsFragment extends Fragment {

    private List<User> list;
    private RecyclerView recyclerView;
    private RecyclerAdapter adapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view =  inflater.inflate(R.layout.fragment_settings, container, false);
        initData(); //初始化数据
        initView(view); //初始化视图
        return view;
    }

    private void initView(View view) {
        recyclerView = view.findViewById(R.id.recyclerView); //绑定控件

        //创建适配器和布局管理器
        adapter = new RecyclerAdapter(list);
        LinearLayoutManager manager = new LinearLayoutManager(view.getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);

        //设置适配器和布局管理器
        recyclerView.setLayoutManager(manager);
        recyclerView.setHasFixedSize(true);
        recyclerView.setAdapter(adapter);
    }

    private void initData() {
        list = new ArrayList<>();
        list.add(new User("Mike", "111111111111111111111111111111", R.drawable.user01));
        list.add(new User("Jack", "222222222222222222222222222222", R.drawable.user02));
        list.add(new User("Jenny", "333333333333333333333333333333", R.drawable.user03));
        list.add(new User("Tom", "444444444444444444444444444444", R.drawable.user04));
        list.add(new User("Jerry", "555555555555555555555555555555", R.drawable.user05));
        list.add(new User("layton", "66666666666666666666666666666", R.drawable.user06));
    }
}